package com.hz.ruoyiequipment.data.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hz.ruoyiequipment.data.domain.AgrEquipmentQx;
import com.hz.ruoyiequipment.data.domain.vo.QxEquipment;
import com.hz.ruoyiequipment.data.domain.vo.QxTimeData;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * @Author: xqd
 * @CreateDate: 2025/03/06/10:29
 * @Description: 气象设备表接口
 */
public interface AgrEquipmentQxMapper extends BaseMapper<QxEquipment> {

    /**
     * @param agrEquipmentQx 气象设备实体类
     * @return: 改变行数（大于0，新增成功）
     * @Author: xqd
     * @Date: 2025/3/8 10:04
     * @Description: 新增设备到气象设备表
     */
    @Insert("INSERT INTO agr_equipment_qx (equipment_id, qx_flow, qx_material, qx_interval, qx_capacity, qx_interface,create_time) " +
            "value (#{equipmentId}, #{qxFlow}, #{qxMaterial}, #{qxInterval}, #{qxCapacity}, #{qxInterface},#{createTime})")
    Integer insertAgrEquipmentQx(AgrEquipmentQx agrEquipmentQx);

    /**
     * @param equipmentId 设备ID
     * @return:
     * @Author: xqd
     * @Date: 2025/3/8 16:51
     * @Description: 查看设备是否绑定地块
     */
    @Select("SELECT equipment_id FROM agr_equipment_plots WHERE equipment_id = #{equipmentId}")
    Integer getEquipmentId(Long equipmentId);

    /**
     * @param qxEquipment QxEquipment实体类
     * @return:
     * @Author: xqd
     * @Date: 2025/3/8 16:52
     * @Description: 修改气象设备表中的数据
     */
    Integer updateAgrEquipmentQx(QxEquipment qxEquipment);

    /**
     * @param qxEquipment QxEquipment实体类
     * @return:
     * @Author: xqd
     * @Date: 2025/3/8 16:53
     * @Description: 修改设备地块表中设备绑定的地块
     */
    Integer updateAgrEquipmentPlot(QxEquipment qxEquipment);

    /**
     * @return:
     * @Author: xqd
     * @Date: 2025/3/8 16:54
     * @Description: 将设备绑定的地块信息插入到设备地块表中
     */
    Integer insertAgrEquipmentPlot(QxEquipment qxEquipment);

    /**
     * @return:
     * @Author: xqd
     * @Date: 2025/3/8 16:55
     * @Description: 删除气象设备表中的数据
     */
    @Delete("DELETE FROM agr_equipment_qx WHERE equipment_id = #{equipmentId}")
    void delAgrEquipmentQxByEquipmentId(Long equipmentId);

    /**
     * @return:
     * @Author: xqd
     * @Date: 2025/3/8 16:55
     * @Description: 删除设备地块表中设备绑定的地块
     */
    @Delete("DELETE FROM agr_equipment_plots WHERE equipment_id = #{equipmentId}")
    void delAgrEquipmentPlotByEquipmentId(Long equipmentId);


    //获取实时数据
    QxTimeData getQxTimeData(Long equipmentId);

    //获取历史数据
    List<QxTimeData> getQxTimeDatas(Long equipmentId);

    //获取数据头部
    QxEquipment getQxTimeDataHead(Long equipmentId);


    @Insert("INSERT INTO agr_environmental_data " +
            "(equipment_id,record_date,wind_speed,wind_direction,atmo_humidity," +
            " atmo_temperature,atmo_pressure, env_light,coo_density,  env_pm) " +
            "VALUES (#{equipmentId}, #{recordDate}, #{windSpeed}, #{windDirection}, #{atmoHumidity}," +
            " #{atmoTemperature}, #{atmoPressure},#{envLight},#{cooDensity},#{envPm})")
    int insertQxTimeData(QxTimeData qxTimeData);

}
